<template>
    <div class="list2">
        <!-- 头部 -->
        <!-- <div class="header">
            <x-icon type="ios-arrow-left" size="" class="icon-white" @click="$router.go(-1)"></x-icon>选择被检查单位
        </div> -->
        <!-- 内容部分 -->
        <div class="list2_main">
            <!-- 没数据图片展示 -->
            <!-- <noData v-if="listArr == 0&&listArr2==0"></noData>  -->

            <div class="list2Box">
                <!-- <div class="search"><input type="text" v-model="param.data.Name"> </div> -->
                <div class="searchDiv" v-if="input">
                    <input type="text" v-model="param.data.Name" class="search" placeholder="输入关键字搜索">
                </div>
                <div class="tree-menu" v-show="searchList">
                    <noData v-if="listArr == 0"></noData>
                    <ul v-for="(menuItem,index) in listArr" :key="index">
                    <my-tree :model="menuItem"></my-tree>
                    </ul>
                </div>
                <div v-for="(item,index) in  listArr2"
                    :key="index"
                    class="item-wrap"
                    v-show="!searchList">
                    <standardItem3 :item="item" :selectStandard="selectStandard"></standardItem3>
                </div>
            </div>
        </div>
        <myMenu @clickBack="back" ></myMenu>
    </div>
</template>
<script>
// import standardItem from './select1'
import myTree from './treemenu'
import standardItem3 from './select3'
import myMenu from '@/commonComponents/menu'
import { XHeader,Tabbar, TabbarItem, Group, Cell } from 'vux'
export default {
    components: {
        // standardItem,
        standardItem3,
        myMenu,
        Tabbar,
        TabbarItem,
        Group,
        Cell,
        XHeader,
        myTree,
    },
  data (){
      return {
        show: false,
        results: [{title:'aaa'},{title:'bbb'}],
        value: 'test',
        param:{
            allowPaging:true,
            business:'GetHdProjectsBySearch',
            data:{
                Name:'',
                DepartId:''
            },
            pageIndex:0,
            pageSize:10000,
            tokenId:'D0853C0CE5A6A478F5C613B840394FC3',
            userId:''
        },
        name3:'',
        idArr1:'',
        idArr2:'',
        listArr:[],
        listArr2:[],
        searchList:true,
        input:false
      }
  },
  mounted(){
    var token =JSON.parse(window.localStorage.getItem('userInfo'))
    if(token.departsir==1){
          this.input=true
      }
    this.param.userId=token.userid
    this.param.data.DepartId=token.deptid
    this.dataArr()
    // this.radios=this.$route.query.radios
  },
  watch:{
      'param.data.Name'(val){
          if (val){
              this.dataArr2()
              this.searchList=false
          }else {
              this.dataArr()
              this.searchList=true
          }
      }
  },
  methods: { 
      back(){
          this.param.data.Name=''
      },
    showChild (deptId, item) {
        if (item.Children.length==0){
            console.log(item.Id,123)
            window.sessionStorage.setItem('ids2',item.Id)
            window.sessionStorage.setItem('paramsName',item.Name)
            this.$router.go(-1)
        } else {
            item.open = !item.open
        }
    },
    selectStandard (item) {
        var arr = this.listArr
        var parmas =[]
        var paramsName=[]
        for (var k of arr){
            for(var j of k.Children){
                j.checked=false
                item.checked=true
                if(j.checked){
                    parmas.push(j.Id)
                    paramsName.push(j.Name)
                }
            }
        }
        if (this.listArr2.length>0){
            var arr2 = this.listArr2[0].list
            for (var k of arr2){
                k.checked=false
                item.checked=true
                if(k.checked){
                    parmas.push(k.Id)
                    paramsName.push(k.Name)
                }
            }
        }
        window.sessionStorage.setItem('ids2',parmas)
        window.sessionStorage.setItem('paramsName',paramsName)
    },
    dataArr(){
      this.$axiosAjax.getConfigJson(this.param).then((res)=>{
            if (res.status){
                var arr =res.data.data
                if (window.sessionStorage.getItem('ids2')){
                    var params = JSON.parse(window.sessionStorage.getItem('ids2'))
                    for(var k of arr){
                        for(var j of k.Children){
                            j.checked = false
                            for(var i in params){
                                if(j.Id==params[i]){
                                    j.checked = true
                                }
                            }
                        }
                        k.open=false
                    }
                } else {
                    for(var k of arr){
                        for(var j of k.Children){
                            j.checked = false
                        }
                        k.open=false
                    }
                }
                this.listArr=arr
            }
         }
      )
    },
    dataArr2(){
      this.$axiosAjax.getConfigJson(this.param).then((res)=>{
            if (res.status){
                this.listArr2=[]
                var arr =res.data.data
                var obj ={}
                if (window.sessionStorage.getItem('ids2')){
                    var params = JSON.parse(window.sessionStorage.getItem('ids2'))
                    for(var k of arr){
                        k.checked = false
                        for(var i in params){
                            if(k.Id==params[i]){
                                k.checked = true
                            }
                        }
                    }
                } else {
                    for(var k of arr){
                        k.checked = false
                    }
                }
                obj.list=arr
                this.listArr2.push(obj)
            }
         }
      )
    },
  }
}
function getResult (val) {
  let rs = []
  for (let i = 0; i < 20; i++) {
    rs.push({
      title: `${val} result: ${i + 1} `,
      other: i
    })
  }
  return rs
}
</script>
<style lang="less" scope>
.list2{
    width: 100%;
    height: 100%;
    background-color: #ebeef2;
    .header{
        width: 100%;
        height: 40px;
        line-height: 40px;
        text-align: center;
        position: relative;
        font-size: 18px;
        background: #2269ff;
        color: #fff;
        .vux-x-icon{
            fill:cornsilk;
            position: absolute;
            left: 0;
            top: 5px;
            width: 30px;
            height: 30px;
        }
    }
    .list2_main{
        height: 100%;
        width: 100%;
        background-color: #ebeef2;
        .list2Box{
            width: 100%;
            height: 100%;
            background-color: #fff;
            .searchDiv{
                background-color: #ebeef2;
                padding: 10px 0;
                .search{
                    width: 360px;
                    margin: 0 auto;
                    height: 40px;
                    line-height: 40px;
                    padding-left: 10px;
                    box-sizing: border-box;
                    border-radius: 10px;
                    display: block;
                    border: 1px solid #999;
                }
            }
            .weui-search-bar__cancel-btn{
                display: none;
            }
        }
    }
    .weui-cell:before{
        left: 0;
    }
    .standard-name span{
        margin-left: 20px;
        font-size: 16px;
        color: #000;
    }
    .iconfont{
        margin-left: 20px;
    }
}
</style>
